package com.jishuo.nontax.web.bill;

import com.jishuo.base.annotation.UserAuthority;
import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.GridResult;
import com.jishuo.base.bean.Pagination;
import com.jishuo.base.bean.vo.UserVO;
import com.jishuo.base.config.AppConfig;
import com.jishuo.base.service.UserService;
import com.jishuo.nontax.bean.vo.ChargeBillVO;
import com.jishuo.nontax.bfc.service.ChargeBillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 缴款书
 */
@Slf4j
@Controller
@RequestMapping(value = "/bill/chargebill", name = "缴款书")
@UserAuthority(menu = {"bill/chargebill/chargebill"})
public class ChargeBillController {
    @Resource
    private ChargeBillService chargeBillService;
    @Resource
    private UserService userService;

    // 页面文件位置
    private String prefix = "bill/";

    @RequestMapping(value = {"chargebill"}, name = "缴款书首页")
    public String index() {
        return prefix + "chargebill";
    }


    /**
     * @author hlp
     * @date 2023/3/2 14:22
     * @Description:  缴款书列表分页
     */
    @ResponseBody
    @RequestMapping(value = "listChargeBill", name = "缴款书列表")
    public GridResult<ChargeBillVO> listChargeBill(ChargeBillVO chargeBillVO, Pagination pagination) {
        return new GridResult<>(this.chargeBillService.listChargeBill(chargeBillVO, pagination));
    }

    /**
     * @author hlp
     * @date 2023/3/6 17:42
     * @Description:  发送缴款书信息
     */
    @ResponseBody
    @RequestMapping(value = "sendChargebill", name = "发送缴款书信息")
    public BaseResult sendChargebill(String billids, String usercode, String userpwd, HttpSession session){
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return chargeBillService.sendChargebill(billids);
    }

    /**
     * @author hlp
     * @date 2023/3/7 14:27
     * @Description: 冲销缴款书信息
     */
    @ResponseBody
    @RequestMapping(value = "cleanChargebill", name = "冲销缴款书信息")
    public BaseResult cleanChargebill(String billids, String usercode, String userpwd, HttpSession session) throws Exception {
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return chargeBillService.cleanChargebill(billids, usercode);
    }

    /**
     * @author hlp
     * @date 2023/3/7 15:20
     * @Description: 缴款书导出
     */
    @ResponseBody
    @RequestMapping(value = "chargebillExport", name = "缴款书导出")
    public void chargebillExport(long bankid, String paybankdt, HttpServletResponse response) throws IOException {
        chargeBillService.listChargeBillExport(bankid, paybankdt, response);
    }

}
